home *** CD-ROM | disk | FTP | other *** search
/ One Click 27 / CD da revista One Click #27 - Photoshop Megapack (2005).iso / Interface / it.dig / scripts / __Packages / mx / data / binding / ComponentMixins.as < prev    next >
Encoding:
Text File  |  2005-10-28  |  8.7 KB  |  290 lines

  1. class mx.data.binding.ComponentMixins
  2. {
  3.    var __refreshing;
  4.    var __bindings;
  5.    var __schema;
  6.    var __fieldCache;
  7.    var _eventDispatcher;
  8.    var dispatchQueue;
  9.    var __highPrioEvents;
  10.    var _databinding_original_dispatchEvent;
  11.    function ComponentMixins()
  12.    {
  13.    }
  14.    function refreshFromSources()
  15.    {
  16.       if(this.__refreshing != null)
  17.       {
  18.          return undefined;
  19.       }
  20.       this.__refreshing = true;
  21.       _global.__dataLogger.logData(this,"Refreshing from sources");
  22.       _global.__dataLogger.nestLevel = _global.__dataLogger.nestLevel + 1;
  23.       mx.data.binding.Binding.refreshFromSources(this,null,this.__bindings);
  24.       _global.__dataLogger.nestLevel--;
  25.       this.__refreshing = null;
  26.    }
  27.    function refreshDestinations()
  28.    {
  29.       _global.__dataLogger.logData(this,"Refreshing Destinations");
  30.       _global.__dataLogger.nestLevel = _global.__dataLogger.nestLevel + 1;
  31.       mx.data.binding.Binding.refreshDestinations(this,this.__bindings);
  32.       _global.__dataLogger.nestLevel--;
  33.    }
  34.    function validateProperty(property, initialMessages)
  35.    {
  36.       var _loc4_ = null;
  37.       var _loc3_ = this.getField(property);
  38.       if(_loc3_ != null)
  39.       {
  40.          _loc4_ = _loc3_.validateAndNotify(null,null,initialMessages);
  41.       }
  42.       else
  43.       {
  44.          _global.__dataLogger.logData(this,"Can\'t validate property \'<property>\' because it doesn\'t exist",{property:property});
  45.       }
  46.       return _loc4_;
  47.    }
  48.    function addBinding(binding)
  49.    {
  50.       if(this.__bindings == undefined)
  51.       {
  52.          this.__bindings = new Array();
  53.       }
  54.       this.__bindings.push(binding);
  55.       var _loc3_ = false;
  56.       if(binding.source.component == this)
  57.       {
  58.          this.getField(binding.source.property,binding.source.location);
  59.          _loc3_ = true;
  60.       }
  61.       if(binding.dest.component == this)
  62.       {
  63.          this.getField(binding.dest.property,binding.dest.location);
  64.          _loc3_ |= Object(binding).is2way;
  65.       }
  66.       if(_loc3_)
  67.       {
  68.          var _loc4_ = binding.dest.component.findSchema(binding.dest.property,binding.dest.location);
  69.          if(_loc4_.readonly)
  70.          {
  71.             binding.source.component.__setReadOnly(true);
  72.          }
  73.       }
  74.    }
  75.    static function initComponent(component)
  76.    {
  77.       var _loc2_ = mx.data.binding.ComponentMixins.prototype;
  78.       if(component.refreshFromSources == undefined)
  79.       {
  80.          component.refreshFromSources = _loc2_.refreshFromSources;
  81.       }
  82.       if(component.refreshDestinations == undefined)
  83.       {
  84.          component.refreshDestinations = _loc2_.refreshDestinations;
  85.       }
  86.       if(component.validateProperty == undefined)
  87.       {
  88.          component.validateProperty = _loc2_.validateProperty;
  89.       }
  90.       if(component.createFieldAccessor == undefined)
  91.       {
  92.          component.createFieldAccessor = _loc2_.createFieldAccessor;
  93.       }
  94.       if(component.createField == undefined)
  95.       {
  96.          component.createField = _loc2_.createField;
  97.       }
  98.       if(component.addBinding == undefined)
  99.       {
  100.          component.addBinding = _loc2_.addBinding;
  101.       }
  102.       if(component.findSchema == undefined)
  103.       {
  104.          component.findSchema = _loc2_.findSchema;
  105.       }
  106.       if(component.getField == undefined)
  107.       {
  108.          component.getField = _loc2_.getField;
  109.       }
  110.       if(component.refreshAndValidate == undefined)
  111.       {
  112.          component.refreshAndValidate = _loc2_.refreshAndValidate;
  113.       }
  114.       if(component.getFieldFromCache == undefined)
  115.       {
  116.          component.getFieldFromCache = _loc2_.getFieldFromCache;
  117.       }
  118.       if(component.getBindingMetaData == undefined)
  119.       {
  120.          component.getBindingMetaData = _loc2_.getBindingMetaData;
  121.       }
  122.       if(component.__setReadOnly == undefined)
  123.       {
  124.          component.__setReadOnly = _loc2_.__setReadOnly;
  125.       }
  126.       if(component.__addHighPrioEventListener == undefined)
  127.       {
  128.          component.__addHighPrioEventListener = _loc2_.__addHighPrioEventListener;
  129.       }
  130.    }
  131.    function createFieldAccessor(property, location, mustExist)
  132.    {
  133.       return mx.data.binding.FieldAccessor.createFieldAccessor(this,property,location,mx.data.binding.FieldAccessor.findElementType(this.__schema,property),mustExist);
  134.    }
  135.    function findSchema(property, location)
  136.    {
  137.       if(typeof location == "string")
  138.       {
  139.          if(!mx.data.binding.FieldAccessor.isActionScriptPath(String(location)))
  140.          {
  141.             return null;
  142.          }
  143.          location = location.split(".");
  144.       }
  145.       var _loc5_ = mx.data.binding.FieldAccessor.findElementType(this.__schema,property);
  146.       if(location != null)
  147.       {
  148.          if(location.path != null)
  149.          {
  150.             location = location.path;
  151.          }
  152.          if(!(location instanceof Array))
  153.          {
  154.             return null;
  155.          }
  156.          var _loc2_ = 0;
  157.          while(_loc2_ < location.length)
  158.          {
  159.             var _loc4_ = location[_loc2_];
  160.             _loc5_ = mx.data.binding.FieldAccessor.findElementType(_loc5_,_loc4_);
  161.             _loc2_ = _loc2_ + 1;
  162.          }
  163.       }
  164.       return _loc5_;
  165.    }
  166.    function createField(property, location)
  167.    {
  168.       var _loc3_ = this.findSchema(property,location);
  169.       var _loc2_ = undefined;
  170.       if(_loc3_.validation != null)
  171.       {
  172.          _loc2_ = mx.data.binding.Binding.getRuntimeObject(_loc3_.validation);
  173.       }
  174.       else
  175.       {
  176.          _loc2_ = new mx.data.binding.DataType();
  177.       }
  178.       _loc2_.setupDataAccessor(this,property,location);
  179.       return _loc2_;
  180.    }
  181.    static function deepEqual(a, b)
  182.    {
  183.       if(a == b)
  184.       {
  185.          return true;
  186.       }
  187.       if(typeof a != typeof b)
  188.       {
  189.          return false;
  190.       }
  191.       if(typeof a != "object")
  192.       {
  193.          return false;
  194.       }
  195.       var _loc3_ = new Object();
  196.       for(var _loc4_ in a)
  197.       {
  198.          if(!mx.data.binding.ComponentMixins.deepEqual(a[_loc4_],b[_loc4_]))
  199.          {
  200.             return false;
  201.          }
  202.          _loc3_[_loc4_] = 1;
  203.       }
  204.       for(_loc4_ in b)
  205.       {
  206.          if(_loc3_[_loc4_] != 1)
  207.          {
  208.             return false;
  209.          }
  210.       }
  211.       return true;
  212.    }
  213.    function getFieldFromCache(property, location)
  214.    {
  215.       for(var _loc5_ in this.__fieldCache)
  216.       {
  217.          var _loc2_ = this.__fieldCache[_loc5_];
  218.          if(_loc2_.property == property && mx.data.binding.ComponentMixins.deepEqual(_loc2_.location,location))
  219.          {
  220.             return _loc2_;
  221.          }
  222.       }
  223.       return null;
  224.    }
  225.    function getField(property, location)
  226.    {
  227.       var _loc2_ = this.getFieldFromCache(property,location);
  228.       if(_loc2_ != null)
  229.       {
  230.          return _loc2_;
  231.       }
  232.       _loc2_ = this.createField(property,location);
  233.       if(this.__fieldCache == null)
  234.       {
  235.          this.__fieldCache = new Array();
  236.       }
  237.       this.__fieldCache.push(_loc2_);
  238.       return _loc2_;
  239.    }
  240.    function refreshAndValidate(property)
  241.    {
  242.       _global.__dataLogger.logData(this,"Refreshing and validating " + property);
  243.       _global.__dataLogger.nestLevel = _global.__dataLogger.nestLevel + 1;
  244.       var _loc3_ = mx.data.binding.Binding.refreshFromSources(this,property,this.__bindings);
  245.       _loc3_ = this.validateProperty(property,_loc3_);
  246.       _global.__dataLogger.nestLevel--;
  247.       return _loc3_ == null;
  248.    }
  249.    function getBindingMetaData(name)
  250.    {
  251.       return this["__" + name];
  252.    }
  253.    function __setReadOnly(setting)
  254.    {
  255.       if(Object(this).editable != undefined)
  256.       {
  257.          Object(this).editable = !setting;
  258.       }
  259.    }
  260.    function __addHighPrioEventListener(event, handler)
  261.    {
  262.       var _loc3_ = this._eventDispatcher == undefined ? this : this._eventDispatcher;
  263.       if(_loc3_.__highPrioEvents == undefined)
  264.       {
  265.          _loc3_.__highPrioEvents = new Object();
  266.       }
  267.       var _loc4_ = "__q_" + event;
  268.       if(_loc3_.__highPrioEvents[_loc4_] == undefined)
  269.       {
  270.          _loc3_.__highPrioEvents[_loc4_] = new Array();
  271.       }
  272.       _global.ASSetPropFlags(_loc3_.__highPrioEvents,_loc4_,1);
  273.       mx.events.EventDispatcher._removeEventListener(_loc3_.__highPrioEvents[_loc4_],event,handler);
  274.       _loc3_.__highPrioEvents[_loc4_].push(handler);
  275.       if(_loc3_._databinding_original_dispatchEvent == undefined)
  276.       {
  277.          _loc3_._databinding_original_dispatchEvent = _loc3_.dispatchEvent;
  278.          _loc3_.dispatchEvent = function(eventObj)
  279.          {
  280.             if(eventObj.target == undefined)
  281.             {
  282.                eventObj.target = this;
  283.             }
  284.             this.dispatchQueue(this.__highPrioEvents,eventObj);
  285.             this._databinding_original_dispatchEvent(eventObj);
  286.          };
  287.       }
  288.    }
  289. }
  290.